class FlashcardsController < ApplicationController
  # GET /flashcards
  # GET /flashcards.xml
  def index
    @flashcards = Flashcard.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @flashcards }
    end
  end

  # GET /flashcards/1
  # GET /flashcards/1.xml
  def show
    @flashcard = Flashcard.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @flashcard }
    end
  end

  # GET /flashcards/new
  # GET /flashcards/new.xml
  def new
    @flashcard = Flashcard.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @flashcard }
    end
  end

  # GET /flashcards/1/edit
  def edit
    @flashcard = Flashcard.find(params[:id])
  end

  # POST /flashcards
  # POST /flashcards.xml
  def create
    @flashcard = Flashcard.new(params[:flashcard])

    respond_to do |format|
      if @flashcard.save
        flash[:notice] = 'Flashcard was successfully created.'
        format.html { redirect_to(@flashcard) }
        format.xml  { render :xml => @flashcard, :status => :created, :location => @flashcard }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @flashcard.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /flashcards/1
  # PUT /flashcards/1.xml
  def update
    @flashcard = Flashcard.find(params[:id])

    respond_to do |format|
      if @flashcard.update_attributes(params[:flashcard])
        flash[:notice] = 'Flashcard was successfully updated.'
        format.html { redirect_to(@flashcard) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @flashcard.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /flashcards/1
  # DELETE /flashcards/1.xml
  def destroy
    @flashcard = Flashcard.find(params[:id])
    @flashcard.destroy

    respond_to do |format|
      format.html { redirect_to(flashcards_url) }
      format.xml  { head :ok }
    end
  end
end
